package com.sky.controller.user;

import com.sky.entity.Setmeal;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@Slf4j
@RequestMapping("/user/setmeal")
@Tag(name = "套餐管理",description = "套餐管理相关接口")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 根据分类id查询套餐信息
     * @param categoryId
     * @return
     */
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    @GetMapping("/list")
    @Operation(summary = "根据分类id查询套餐信息")
    public Result<List<Setmeal>> getSetmealsByCategoryId(Long categoryId){
        log.info("根据分类id查询套餐信息：{}",categoryId);
        List<Setmeal> categoryList = setmealService.getSetmealsByCategoryId(categoryId);
        return Result.success(categoryList);
    }

    /**
     * 查询套餐中的菜品
     * @param id
     * @return
     */
    @Operation(summary = "查询套餐中的菜品")
    @GetMapping("/dish/{id}")
    public Result<List> getDishesBySetmealId(@PathVariable Long id){
        log.info("根据套餐id查询套餐中的菜品：{}",id);
        List<DishItemVO> dishItemVOList = setmealService.getDishesBySetmealId(id);
        return Result.success(dishItemVOList);
    }

}
